package com.inspur.edp.web.formmetadata.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class UiLanguageResourceRequestWrapper extends HttpServletRequestWrapper {
    private final String newURI;
    /**
     * Constructs a request object wrapping the given request.
     *
     * @param request the {@link HttpServletRequest} to be wrapped.
     * @throws IllegalArgumentException if the request is null
     */
    public UiLanguageResourceRequestWrapper(HttpServletRequest request, String newURI) {
        super(request);
        this.newURI = newURI;
    }

    @Override
    public String getRequestURI() {
        return newURI;
    }

    @Override
    public StringBuffer getRequestURL() {
        StringBuffer original = super.getRequestURL();
        return original.replace(0, original.length(),
                super.getScheme() + "://" + super.getServerName() +
                        (super.getServerPort() == 80 || super.getServerPort() == 443 ? "" : ":" + super.getServerPort()) +
                        newURI);
    }
}
